package com.ericsson.enap.modules.ebmLog.task.vgc;

import com.ericsson.common.util.FileUtil;
import com.ericsson.common.util.LogFileName;
import com.ericsson.common.util.LoggerUtils;
import com.ericsson.enap.modules.ebmLog.entity.EbmEventVO;
import org.slf4j.Logger;

import java.io.File;
import java.util.Map;
import java.util.concurrent.CountDownLatch;

import static com.ericsson.enap.modules.ebmLog.constant.VgcEbmConstant.BIN;
import static com.ericsson.enap.modules.ebmLog.utils.VgcEbmLogUtil.executeCmd;

/**
 * @description:执行世凯脚本，并生成csv文件任务
 * @author: wangjingshi
 * @create: 2021-11-10 10:12
 */
public class VgcEbmExecuteScriptTask implements Runnable{

    private final Logger log = LoggerUtils.Logger(LogFileName.VgcEbmLogJob);
    private String netid;
    private String localPath;
    private CountDownLatch latch;

    public VgcEbmExecuteScriptTask(String netid, String localPath, CountDownLatch latch) {
        this.netid = netid;
        this.localPath = localPath;
        this.latch = latch;
    }

    @Override
    public void run() {
        try {
            File file = new File(localPath);
            log.info(netid + " ===== localPath:" + localPath);
            FileUtil.newDirs(file);
            String[] files = file.list();
            for(int i=0;i<files.length;i++){
                String cmd = BIN + "parse_ebm -b " + localPath + files[i] + " -x " + BIN + "ebm.xml " + " -p " + BIN + "enip_params.txt -f csv";
                executeCmd(cmd);
            }
        } catch (Exception e) {
            log.error(e.getMessage(),e);
        } finally {
            latch.countDown();
        }

    }
}
